<?php

namespace App\Admin\Actions;

use App\Exceptions\Arr;
use App\Models\AppointNum;
use App\Models\HospitalAppoint;
use App\Models\HospitalAppointInterval;
use App\Models\HospitalAppointIntervalNum;
use App\Models\HospitalAppointStreet;
use App\Models\HospitalAppointVaccine;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Show;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Alert;
use Dcat\Admin\Grid\RowAction;


class HospitalAppointVaccineDeleteAction extends RowAction
{
    /**
     * 返回字段标题
     *
     * @return string
     */
    public function title()
    {
        return '删除';
    }

    /**
     * 添加JS
     *
     * @return string
     */
    protected function script()
    {
        return <<<JS
$('.hospital-appoint-vaccine-delete').on('click', function () {

    var id = $(this).data('id');
    Dcat.confirm('确认要删除这行数据吗？', null, function () {
        console.log('确认删除'+id);
        $.ajax({
            url:'hospital-appoint-vaccine/'+id,
            type:'DELETE',
            success:function(res){
                console.log(res);
                Dcat.success('删除成功');
                setTimeout(function () {
                    Dcat.reload();
                }, 1000);
            },
            error:function(res){
                console.log(res);
                Dcat.success('删除失败');

            }
        });
    });
});
JS;
    }

    public function html()
    {
        // 获取当前行数据ID
        $id = $this->getKey();

        // 这里需要添加一个class, 和上面script方法对应
        $this->setHtmlAttribute(['data-id' => $id,'class' => 'hospital-appoint-vaccine-delete']);

        return parent::html();
    }
}

